package com.cskaoyan.controller.permissiondata;

import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.po.MarketAdminPermission;
import com.cskaoyan.mapper.MarketAdminPermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: Yang Yi-zhou
 * @Date: 2022/9/9 09:15
 * @Description:
 */
@RestController
public class DataController {

    @Autowired
    MarketAdminPermissionMapper marketAdminPermissionMapper;

    @RequestMapping("permissions")
    public BaseRespVo importPermissions(@RequestBody List<PermissionData> permissionDataList) {
        for (PermissionData permissionData : permissionDataList) {
            for (PermissionData.ChildrenDTO child : permissionData.getChildren()) {
                for (PermissionData.ChildrenDTO.GrandChildrenDTO grandChildrenDTO : child.getChildren()) {
                    MarketAdminPermission marketAdminPermission = new MarketAdminPermission();
                    marketAdminPermission.setModuleLable(permissionData.getLabel());
                    marketAdminPermission.setTypeLable(child.getLabel());
                    marketAdminPermission.setApi(grandChildrenDTO.getApi());
                    marketAdminPermission.setApiId(grandChildrenDTO.getId());
                    marketAdminPermission.setApiLable(grandChildrenDTO.getLabel());
                    marketAdminPermissionMapper.insertSelective(marketAdminPermission);
                }
            }
        }

        return BaseRespVo.ok();
    }
}
